{include file="public/_meta" /}
<body>
<style>
    .required_b{
        color: red;
    }
</style>
<div class="wrapper">

    {include file="public/_header" /}

    <!-- Sidebar -->
    {include file="public/_menu" /}
    <!-- End Sidebar -->

    <div class="main-panel">

        <div class="content">
            <div class="page-inner">

                <!-- 面包屑 -->
                {include file="public/_page_header" /}

                <div class="row">
                    <div class="col-md-12">
                        <div class="card">
                            <div class="card-header">
                                <div class="d-flex align-items-center">
                                    <h4 class="card-title">收支汇总</h4>

                                </div>

                                <form class="row" id="selectform">

                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <input type="text" class="form-control" name="times" id="times" value="{$times}" placeholder="日期" autocomplete="off">
                                        </div>
                                    </div>
                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">

                                            <select class="form-control input-full" name="pro_id" id="pro_id">
                                                <option value="">全部产品</option>
                                                {volist name="products" id="vo"}
                                                <option value="{$key}">{$vo}</option>
                                                {/volist}
                                            </select>
                                        </div>
                                    </div>

                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <input type="text" class="form-control" name="cityname" value="{$cityname}" placeholder="请输入城市">
                                        </div>
                                    </div>

                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <input type="text" class="form-control" name="lirunw" value="{$lirunw}" placeholder="利润<=（填写金额）高亮显示">
                                        </div>
                                    </div>


                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <button type="submit" class="btn btn-primary">查询</button>
                                            <a href="{:url('bindex/moneyCollectCity')}" class="btn btn-info" style="color: white;position: absolute;left: 100px;">重置</a>
                                        </div>
                                    </div>

                                </form>

                            </div>
                            <div class="layui-card-body">

                                <blockquote class="layui-elem-quote layui-quote-nm">
                                    <span style="margin-right: 50px;">账户币支出：{$money}</span><span style="margin-right: 50px;">真实币支出：{$true_consume}</span><span style="margin-right: 50px;">进线线索量：{$num}</span><span style="margin-right: 50px;">分发金额：{$push_price}</span>
                                    <span style="margin-right: 50px;">分发数量：{$push_num}</span><span style="margin-right: 50px;">毛利：{$lirun}</span><span style="margin-right: 50px;">毛利率：{$lirun_rate}%</span>

                                </blockquote>
                            </div>


                            <div class="card-body">
                                <!-- Modal -->


                                <div class="table-responsive">
                                    <table id="add-row" class="display table table-striped table-hover" >
                                        <thead>
                                        <tr>
                                            <th>日期</th>
                                            <th>产品</th>
                                            <th>城市</th>
                                            <th>账户币支出</th>
                                            <th>真实币支出</th>
                                            <th>进线线索量</th>
                                            <th>分发金额</th>
                                            <th>分发数量 </th>
                                            <th>毛利</th>
                                            <th>毛利率</th>
                                        </tr>
                                        </thead>

                                        <tbody>

                                        {volist name="list" id="vo"}
                                        <tr>

                                            <td>
                                               {$vo.days}
                                            </td>
                                            <td>{$vo.pro_name}</td>
                                            <td>{$vo.city_name}</td>
                                            <td>
                                                {$vo.money}
                                            </td>
                                            <td>
                                                {$vo.true_consume}
                                            </td>
                                            <td>
                                                {$vo.num}
                                            </td>
                                            <td>
                                                {$vo.push_price}
                                            </td>
                                            <td>
                                                {$vo.push_num}
                                            </td>
                                            <td>
                                                {$vo.lirun}
                                            </td>

                                            <td>{$vo.lirun_rate}%
                                            </td>

                                        </tr>
                                        {/volist}

                                        </tbody>
                                    </table>

                                    <!-- 分页 (调取通用方法)-->
                                     <div class="layui-box layui-laypage layui-laypage-molv">{:pagination($infos)}</div>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>


            </div>
        </div>

        {include file="public/_footer" /}


    </div>



</div>

{include file="public/_js" /}

</body>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
    var SCOPE = {
        'status_url':"{:url('clue/status')}",
        'delete_url':"{:url('clue/delete')}",
        'item_url':"{:url('clue/edit')}",
        'item_url2':"{:url('clue/edit2')}",
        'add_url':"{:url('clue/save')}",
        'clue_url':"{:url('clue/clue_url')}",
        'city_url':"{:url('clue/getRegion')}",
        'push_rule':"{:url('clue/getMerchantPush')}",
        'push_url':"{:url('clue/findPush')}",
        'get_account':"{:url('stat/getAccount')}",
        'saveclue':"{:url('stat/saveClueCost')}",
        'editclue':"{:url('stat/editClueCost')}",
        'del_clue':"{:url('stat/delClueCost')}",
        'improtexcel':"{:url('stat/importClueCost')}",
    };


    function loadRule(sel,selName){
        $("#"+selName+" option").each(function(){
            $(this).remove();
        });
        $("<option value=0>请选择</option>").appendTo($("#"+selName));
        if($("#"+sel).val()==0){
            return;
        }
        $.post(SCOPE.get_account,{pid:$("#"+sel).val()},
            function(data){
                if(data.code == 1001){
                    $.each(data.data,function(k,v) {
                        $("<option value='"+v.id+"'>【"+v.acc_name+"】【账号ID"+v.adv_id+"】</option>").appendTo($("#"+selName));
                    });
                }else{
                    $("<option value='0'>请选择</option>").appendTo($("#"+selName));
                }
            }
        );
    }

    function loadRegion(sel,type_id,selName){
        $("#"+selName+" option").each(function(){
            $(this).remove();
        });
        $("<option value=0>请选择</option>").appendTo($("#"+selName));
        if($("#"+sel).val()==0){
            return;
        }
        $.post(SCOPE.city_url,{pid:$("#"+sel).val(),type:type_id},
            function(data){
                if(data.code == 1001){
                    $.each(data.data,function(idx,item){
                        $("<option value="+item.id+">"+item.name+"</option>").appendTo($("#"+selName));
                    });
                }else{
                    $("<option value='0'>请选择</option>").appendTo($("#"+selName));
                }
            }
        );
    }

    $(function(){
        var commitStatus = false;
        /*表单验证*/
        $("#form-modal").validate({
            rules:{
                clue_name:{
                    required:true,
                    maxlength:30
                },
                phone:{
                    required:true,
                    number:true,
                    minlength:11,
                    maxlength:11
                },
                age:{
                    number:true
                },
                email:{
                    email:true,
                    maxlength:100
                },
                wx_id:{
                    maxlength:30
                },
                qq:{
                    maxlength:30
                },
                remark:{
                    maxlength:300
                }

            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var url = SCOPE.saveclue;
                if(commitStatus==true){
                    return false;
                }
                var province = $("#province").val();
                var city = $("#city").val();
                if(province != 0 && city == 0){
                    layer.msg('请选择市/县',{icon:2,time:2000});
                    return false;
                }
                /*表单提交*/
                $(form).ajaxSubmit({
                    type: 'post',
                    url: url,
                    success: function(data){
                        if(data.code == 1001){
                            commitStatus = true;
                            layer.msg(data.msg, {
                                icon: 1,
                                time: 2000
                            }, function(){
                                parent.location.reload();
                            });
                        }else{
                            layer.msg(data.msg,{icon:2,time:2000});
                        }
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer.msg(errorThrown,{icon:2,time:2000});
                    }
                });

            }
        });

    });

    function del(){
        //询问框

        layer.confirm('确定要删除当前查询的数据？', {
            btn: ['确认','取消'] //按钮
        }, function(){

            /*表单提交*/
            $("#selectform").ajaxSubmit({
                type: 'post',
                url: "{:url('stat/delClueCostAll')}",
                success: function(data){
                    if(data.code == 1001){
                        commitStatus = true;
                        layer.msg(data.msg, {
                            icon: 1,
                            time: 2000
                        }, function(){
                            parent.location.reload();
                        });
                    }else{
                        layer.msg(data.msg,{icon:2,time:2000});
                    }
                },
                error: function(XmlHttpRequest, textStatus, errorThrown){
                    layer.msg(errorThrown,{icon:2,time:2000});
                }
            });

        }, function(){

        });
    }

    $(function(){
        var commitStatus = false;
        /*表单验证*/
        $("#form-modal2").validate({

            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var url = SCOPE.push_url;
                if(commitStatus==true){
                    return false;
                }

                /*表单提交*/
                $(form).ajaxSubmit({
                    type: 'post',
                    url: url,
                    success: function(data){
                        if(data.code == 1001){
                            commitStatus = true;
                            layer.msg(data.msg, {
                                icon: 1,
                                time: 2000
                            }, function(){
                                parent.location.reload();
                            });
                        }else{
                            layer.msg(data.msg,{icon:2,time:2000});
                        }
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer.msg(errorThrown,{icon:2,time:2000});
                    }
                });

            }
        });

    });

    function add_item(id) {
        $("input[name='id']").val(id);
        document.getElementById('form-modal').reset();
        $("#city").children().remove();
        $("<option value='0'>请选择</option>").appendTo($("#city"));
        $(".fw-mediumbold").text('添加');
    }

    function edit_item(id) {
        $("#city").children().remove();
        $("<option value='0'>请选择</option>").appendTo($("#city"));
        $.ajax({
            type: 'GET',
            url: SCOPE.editclue,
            dataType: 'json',
            data: {id:id},
            success: function(res){
                if(res.code == 1001){
                    $(".fw-mediumbold").text('编辑');
                    $("#id").val(res.data.id);

                    $("#channel").find("option[value="+res.data.channel_id+"]").attr("selected",true);
                    $("#account").children().remove();
                    $("<option value='"+res.data.acc_id+"'>【"+res.data.acc_name+"】【账号ID"+res.data.adv_id+"】</option>").appendTo($("#account"));
                    $("#dtime").val(res.data.time);
                    $("#exposure_val").val(res.data.exposure_val);
                    $("#click_val").val(res.data.click_val);
                    $("#money").val(res.data.money);
                    $("#transform_val").val(res.data.transform_val);
                    $("#clue_num").val(res.data.clue_num);
                    $("#change_cost").val(res.data.change_cost);
                    $("#true_cost").val(res.data.true_cost);
                    $("#true_consume").val(res.data.true_consume);
                    $("#remark").val(res.data.remark);
                    $("#province").val(res.data.prov);
                    if(res.data.city != ''){
                        $("#city").children().remove();
                        $("<option value='"+res.data.city+"'>"+res.data.city_name+"</option>").appendTo($("#city"));
                    }
                }else{
                    layer.msg(res.msg,{icon:2,time:2000});
                }

            },
            error:function(res) {
                layer.msg('网络错误,稍后再试...',{icon:2,time:2000});
            }
        });
    }

    function edit_item2(id,city) {
        $("#mrule").children().remove();
        $("<option value='0'>请选择</option>").appendTo($("#mrule"));
        $.ajax({
            type: 'GET',
            url: SCOPE.item_url2,
            dataType: 'json',
            data: {id:id},
            success: function(res){
                if(res.code == 1001){
                    $(".fw-mediumbold").text('推送');
                    $("#id2").val(res.data.id);
                    $("#clue_name2").val(res.data.clue_name);
                    $("#phone2").val(res.data.phone);

                    $("#remark2").val(res.data.remark);
                    $("#city2").text(city);

                    $("#merchant").children().remove();


                    $.each(res.data.merchant,function(k,v) {
                        $("<option value='"+v.id+"'>【"+v.mer_name+"】【账号"+v.username+"】(联系电话"+v.phone+")</option>").appendTo($("#merchant"));
                    });

                }else{
                    layer.msg(res.msg,{icon:2,time:2000});
                }

            },
            error:function(res) {
                layer.msg('网络错误,稍后再试...',{icon:2,time:2000});
            }
        });
    }



    /*删除*/
    function admin_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                type: 'POST',
                url: SCOPE.del_clue,
                dataType: 'json',
                data: {id:id},
                success: function(data){
                    if(data.code == 1001){
                        $(obj).parents("tr").remove();
                        layer.msg('删除线索成功!',{icon:1,time:2000});
                    }else{
                        layer.msg(data.msg,{icon:2,time:2000});
                    }

                },
                error:function(data) {
                    layer.msg('网络错误,稍后再试...',{icon:2,time:2000});
                }
            });
        });
    }


    /*机构-停用*/
    function admin_stop(obj,id){
        layer.confirm('确认要禁止推送吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……
            var url = SCOPE.status_url;
            $.post(url,{status:2,id:id},function(data){
                if(data.code == 1001){
                    layer.msg('已禁止推送!',{icon: 1,time:1000},function(){
                        window.location.reload();
                    });
                }else{
                    layer.msg(data.msg,{icon: 2,time:1000});
                }

            });


        });
    }

    /*机构-启用*/
    function admin_start(obj,id){
        layer.confirm('确认要推送线索吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……

            var url = SCOPE.status_url;
            $.post(url,{status:1,id:id},function(data){
                if(data.code == 1001){

                    layer.msg('已推送!',{icon: 1,time:1000},function(){
                        window.location.reload();
                    });
                }else{
                    layer.msg(data.msg,{icon: 2,time:1000});
                }
            });
        });
    }

    laydate.render({
        elem: '#times'
        ,type: 'date'
        ,range: true
    });

    //自定义格式
    laydate.render({
        elem: '#dtime'
        ,format: 'yyyy-MM-dd'
    });


$("#pro_id").val('{$pro_id}');



</script>
<script src="__STATIC__/layui/layui.js"></script>
<script>
    layui.use(['upload', 'element', 'layer'], function() {
        var $ = layui.jquery
            , upload = layui.upload
            , element = layui.element
            , layer = layui.layer;

        //选完文件后不自动上传
        upload.render({
            elem: '#test8'
            ,url: "{:url('stat/importClueCost')}" //此处配置你自己的上传接口即可
            ,auto: false
            //,multiple: true
            ,accept:'file'
            ,bindAction: '#test9'
            ,done: function(res){
                if(res.code == 1001){
                    layer.msg(res.msg,{icon: 1,time:1000},function(){
                        window.location.reload();
                    });
                }else{

                    layer.alert(res.msg, {

                        closeBtn: 0
                        ,anim: 4 //动画类型
                    });

                    // layer.msg(res.msg,{icon: 2,time:3000});
                }
            }
        });
    });
</script>
</html>




























